
import config from '@/common/apiConfig.js';
import $http from '@/common/index.js';

const { baseUrl } = config;

const state = () => ({
  input: 1234
});

const mutations = {
  setData(state, s) {
    state.input = s;
  }
};

const actions = {
  // POST
  async demoPost({ commit }, data) {
    try {
      const res = await $http({
        url: baseUrl + '/page/more',
        method: 'POST',
        data
      });
      return res;
    } catch (error) {
      console.error('POST request failed:', error);
      throw error;
    }
  },
  // GET
  async demoGet({ commit }, url) {
    try {
      const res = await $http({
        url: baseUrl + '/page/list',
        method: 'GET'
      });
      return res;
    } catch (error) {
      console.error('GET request failed:', error);
      throw error;
    }
  },
  // 获取字典
  async getDicts({ commit }, name) {
    try {
      const res = await $http({
        url: baseUrl + `/Common/dicts?name=${name}`,
        method: 'GET'
      });
      return res;
    } catch (error) {
      console.error('GET request failed:', error);
      throw error;
    }
  },
};

export default {
  state,
  mutations,
  actions
};